﻿<UserControl x:Class="WpfPopup.CustomTooltipControl"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             mc:Ignorable="d" 
                 xmlns:local="clr-namespace:WpfPopup"
            x:Name="main"
             d:DesignHeight="300" d:DesignWidth="300">
  <UserControl.Resources>
    <local:OffsetConverter x:Key="OffsetConverter" />
  </UserControl.Resources>
  <Grid>
    <Popup  
           x:Name="pop"
           Placement="Bottom"
           HorizontalOffset="{Binding ElementName=gridContent,Path=ActualWidth,Converter={StaticResource OffsetConverter}}"
           AllowsTransparency="True"
           PlacementTarget="{Binding ElementName=main,Path=PlaceTarget}"
           IsOpen="True" StaysOpen="True">
      <Border  >
        <Border.Background>
          <DrawingBrush   AlignmentY="Top" TileMode="None"  Stretch="UniformToFill">
            <DrawingBrush.Drawing>
              <GeometryDrawing  Brush="Black" Geometry="M0,0 L100,0 L105,-5 L110,0 L150,0 L150,50 L0,50 z">
              </GeometryDrawing>
            </DrawingBrush.Drawing>
          </DrawingBrush>
        </Border.Background>
        <Grid x:Name="gridContent">
          <Grid.ColumnDefinitions>
            <ColumnDefinition />
            <ColumnDefinition  Width="30"/>
          </Grid.ColumnDefinitions>
          <TextBlock Text="{Binding TooltipString,ElementName=main}" Width="Auto" Padding="10,10,10,5" FontSize="14" Foreground="White" VerticalAlignment="Center"/>
          <Button Width="12" Height="12" Grid.Column="1"  VerticalAlignment="Center"  x:Name="btnClose"   Click="btnClose_Click" >
            <Button.Style>
              <Style TargetType="Button">
                <Setter Property="Cursor" Value="Hand"/>
                <Setter Property="Template">
                  <Setter.Value>
                    <ControlTemplate TargetType="Button">
                      <Border  Background="Transparent">
                        <ContentPresenter Content="{TemplateBinding Content}" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"  Margin="1"/>
                      </Border>
                    </ControlTemplate>
                  </Setter.Value>
                </Setter>
              </Style>
            </Button.Style>
            <Path Data="M0,0 L5,5 M5,0 L0,5" Stretch="UniformToFill" Stroke="White" />
          </Button>
        </Grid>
      </Border>
    </Popup>

  </Grid>
</UserControl>
